//
//  QYGRootVC.m
//  wawaji_ios
//
//  Created by 奇艺果 on 2018/1/17.
//  Copyright © 2018年 yiguo qi. All rights reserved.
//

#import "QYGRootVC.h"
#import "QYGLoginViewController.h"
#import "QYGConfigModel.h"
#import "QYGNetRequestModel.h"

@interface QYGRootVC ()
@end

@implementation QYGRootVC


- (void)viewDidLoad {
    [super viewDidLoad];
    // 获取配置信息
    [self getConfig];
}
- (void)loadView{
    [super loadView];
    self.view = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"login_bg"]];
}
- (void)getConfig{
    
    // 1.获取当前版本号
    NSString *currVersion = [NSBundle mainBundle].infoDictionary[@"CFBundleShortVersionString"];
    [QYGNetRequestModel getConfigCompleted:^(QYGConfigModel *configDict) {
        [QYGKeychain setPayType:configDict.fake_pay];
        [QYGKeychain setMall_url:configDict.mall_url];
        [QYGKeychain setIsDollTest:![configDict.doll_env isEqualToString:@"production"]];
        NSString *appName;
        if(configDict.app_name.length && configDict.app_name.length >7){
            appName = [configDict.app_name substringToIndex:7];
            appName = [appName stringByAppendingString:@"..."];
        }else{
            appName = configDict.app_name;
        }
        [QYGKeychain setAppName:appName];
        [QYGKeychain setSocket_url:configDict.socket_server_host];
        
        if([currVersion isEqualToString:configDict.auditing_version]){
            [QYGKeychain setIsShowPay:0];
        }else{
            [QYGKeychain setIsShowPay:1];
        }
        // 设置根控制器
        [self showLoginController];
        
    } WithErrorCodeBlock:^(NSError *error) {
    }];
}

#pragma mark－ 设置根控制器
-(void)showLoginController
{
    QYGLoginViewController *loginController=[[QYGLoginViewController alloc] init];
    KeyWindow.rootViewController = loginController;
}

@end
